package com.hanke.mothed;

import com.hanke.Fruits;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MothedInfo extends Fruits implements Mothed{

    //时间进行了固定
    public static String start = "2022-11-15";
    public static String end = "2022-11-20";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public double money1(int x, int y, int z) {
        return f1(x) + f2(y) + f3(z);
    }

    // 促销活动的时间
    @Override
    public double money2(int x, int y, int z) {
        double number = 0;
        try {
            if (new Date().getTime() >= dateFormat.parse(start).getTime() && new Date().getTime() <= dateFormat.parse(end).getTime()) {
                number = f1(x) + f2(y) * 0.8 + f3(z);
            }else {
                number = f1(x) + f2(y) + f3(z);
            }
        } catch (ParseException e) {
            throw new RuntimeException("输出有错误");
        }
        return number;
    }

    //客户D     超市继续加大促销力度，购物满 100 减 10 块。
    @Override
    public double money3(int x, int y, int z) {
        double number = 0;
        try {
            if (System.currentTimeMillis() > dateFormat.parse(start).getTime() && System.currentTimeMillis() < dateFormat.parse(end).getTime()) {
                double m1 = f1(x) + f2(y) * 0.8 + f3(z);
                double m2 = (int) (m1 / 100) * 10;
                number = m1 - m2;
            }else {
                double m1 = f1(x) + f2(y) + f3(z);
                double m2 = (int) (m1 / 100) * 10;
                number = m1 - m2;
            }

        } catch (ParseException e) {
            throw new RuntimeException("输出有错误");
        }
        return number;
    }
}
